import { _decorator, Component, Label, Node, Sprite } from 'cc';
import { BaseItem } from '../../items/BaseItem';
import { _player, _resource } from '../../Main';
import { Coin } from '../../items/common/Coin';
const { ccclass, property } = _decorator;

@ccclass('SignItemSub')
export class SignItemSub extends Component {

    @property(Sprite)
    itemIcon: Sprite = null!

    @property(Label)
    itemAmount: Label = null!

    item: BaseItem = null

    amount: number = 0

    init(item: BaseItem, amount: number) {
        this.item = item
        this.amount = amount
        if (!(item instanceof Coin)) {
            this.itemIcon.spriteFrame = this.item.icon
            _resource.spriteFitSquare(this.itemIcon, 80, 80)
        }
        this.itemAmount.string = '×' + this.amount
    }

    get(multi: number = 1) {
        _player.changeNumData(this.item.getIdName(), this.item.storeAt, this.amount * multi, 'add', true, () => {

        })
    }
}


